package com.example.materialtest

import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.*
import androidx.appcompat.app.AppCompatActivity


class enter : AppCompatActivity() ,View.OnClickListener{
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_enter)
        var getnum=findViewById<Button>(R.id.getnum)
        var enterapp=findViewById<Button>(R.id.enterapp)
        getnum.setOnClickListener (this)
        enterapp.setOnClickListener (this)
    }
    fun customDialog() {
        val builder :AlertDialog.Builder= AlertDialog.Builder(this@enter)
        val dialog :AlertDialog= builder.create()
        val dialogView :View= View.inflate(this@enter,R.layout.activity_come, null)
        dialog.setView(dialogView)
        dialog.show()
        dialog.getWindow()?.setBackgroundDrawableResource(android.R.color.transparent)
        val params = dialog.getWindow()?.getAttributes();
        if (params != null) {
            params.width = 893
        };
        if (params != null) {
            params.height = 657
        };
        dialog.getWindow()?.setAttributes(params);
        val title_enter = dialogView.findViewById<TextView>(R.id.title_enter)
        val ok = dialogView.findViewById<RelativeLayout>(R.id.ok)
        val cancel = dialogView.findViewById<RelativeLayout>(R.id.cancel)
        title_enter.setText("该手机号未授权，请联系信息化室进行授权。")
        title_enter.setTextSize(16F)

        ok.setOnClickListener(View.OnClickListener {
            val intent = Intent(this, RegisterActivity::class.java)
            startActivity(intent)
            finish()
            dialog.dismiss()
        })
        cancel.setOnClickListener(View.OnClickListener {
            Toast.makeText(this,"授权失败",Toast.LENGTH_SHORT).show()
            dialog.dismiss()
        })
    }
    fun getnumfun(){
        var pass=findViewById<EditText>(R.id.pass)
        pass.setText("666666")
    }
    override fun onClick(v: View?) {
        when (v!!.id) {
            R.id.getnum -> getnumfun()
            R.id.enterapp -> {
                var pass=findViewById<EditText>(R.id.pass)
                var phone=findViewById<EditText>(R.id.phone)
                if(phone.text.toString().equals("13955555555")&&pass.text.toString().equals("666666")){ customDialog() }
                else{ Toast.makeText(this,"手机号或验证码输入错误",Toast.LENGTH_SHORT).show() }
            }
        }
    }

}
